package com.yes.xr.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JdbcSelect {
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        String url="jdbc:mysql://localhost:3306/text1?useSSL=false";
        String username="root";
        String password="985211";
        Connection connection = DriverManager.getConnection(url, username, password);

        //创建陈述句对象
        Statement statement = connection.createStatement();

        //执行查询
        String sql="SELECT id,username FROM `user` ORDER BY id";
        ResultSet set = statement.executeQuery(sql);

        //获取数据
        while (set.next()){
            String string = set.getString(2);
            int anInt = set.getInt(1);
            System.out.println("id:"+anInt+" "+"name:"+string);
        }
        /*set.next();
        String string = set.getString(2);
        int anInt = set.getInt(1);
        System.out.println(anInt);
        System.out.println(string);

        set.next();
        int anInt1 = set.getInt(1);
        String string1 = set.getString(2);
        System.out.println(anInt1);
        System.out.println(string1);*/
    }
}
